package homework.two;

import java.util.ArrayList;
import java.util.List;

public class twodemo {

    static List<Student> studentList = new ArrayList<>();
    static List<Score> scoreList = new ArrayList<>();

    static void avg_score(String course){
        int sum = 0, count = 0;
        for(Score s:scoreList){
            if(s.getCourse().equals(course)){
                sum += s.getResult();
                count ++;
            }
        }
        System.out.println(course + "平均成绩：" + sum / count);
    }

    static void maxmin_score(String course){
        int max_score = 0;
        int min_score = 0;
        System.out.println(course + "情况如下：");
        for(Score s:scoreList){
            if(s.getCourse().equals(course)){
                if(max_score < s.getResult()) max_score = s.getResult();
                if(min_score == 0) min_score = s.getResult();
                if(min_score > s.getResult()) min_score = s.getResult();
            }
        }
        System.out.println("最高分是：" + max_score + "\n最低分是：" + min_score);
    }

    static void studnet_score(long number){
        System.out.println("该学生成绩如下");
        for(Score s:scoreList){
            if(s.getNumber() == number){
                System.out.println(s.getCourse() + "：" + s.getResult());
            }
        }
    }

    public static void main(String[] args) {
        // 初始化学生名单和课程成绩单
        Student student1 = new Student(1, "xiaoming", "男", "5班");
        Student student2 = new Student(2, "xiaohong", "女", "5班");
        Student student3 = new Student(3, "xiaogang", "男", "5班");
        studentList.add(student1);
        studentList.add(student2);
        studentList.add(student3);
        Score score1chinese = new Score(1, "语文", 90);
        Score score1math = new Score(1, "数学", 91);
        Score score1english = new Score(1, "英语", 92);
        Score score2chinese = new Score(2, "语文", 93);
        Score score2math = new Score(2, "数学", 94);
        Score score2english = new Score(2, "英语", 95);
        Score score3chinese = new Score(3, "语文", 96);
        Score score3math = new Score(3, "数学", 97);
        Score score3english = new Score(3, "英语", 98);
        scoreList.add(score1chinese);
        scoreList.add(score2chinese);
        scoreList.add(score3chinese);
        scoreList.add(score1math);
        scoreList.add(score2math);
        scoreList.add(score3math);
        scoreList.add(score1english);
        scoreList.add(score2english);
        scoreList.add(score3english);

        //输出每门课程所有学生的平均成绩
        avg_score("语文");
        avg_score("数学");
        avg_score("英语");

        System.out.println("***************");
        //输出某门课程的最高分与最低分
        maxmin_score("数学");

        System.out.println("***************");
        //查询某个学生的所有成绩
        studnet_score(3);
    }
}
